#include "stdafx.h"
#include "wf_editcopy.h"
#include "pf_modification.h"

/**
 * Constructor.
 *
 * @param undo true for undo and false for redo.
 */
WF_EditCopy::WF_EditCopy(bool copy,
                                     PF_Container& container,
                                     PF_GraphicView& graphicView)
        :PF_ActionInterface("Edit Copy",
                    container, graphicView) {

    this->copy = copy;
}



WF_EditCopy::~WF_EditCopy() {}



QAction* WF_EditCopy::createGUIAction(LX_Define::ActionType type, QObject* parent) {
    QAction* action;

    if (type==LX_Define::ActionEditCopy) {
		// tr("Copy")
		action = new QAction(tr("&Copy"), parent);
#if QT_VERSION >= 0x040600
                action->setIcon(QIcon::fromTheme("edit-copy", QIcon(":/actions/editcopy2.png")));
#else
                action->setIcon(QIcon(":/actions/editcopy2.png"));
#endif
		action->setShortcut(QKeySequence::Copy);
		//action->zetStatusTip(tr("Copies entities to the clipboard"));
    } else {
		// tr("Cut")
		action = new QAction(tr("Cu&t"), parent);
#if QT_VERSION >= 0x040600
                action->setIcon(QIcon::fromTheme("edit-cut", QIcon(":/actions/editcut2.png")));
#else
                action->setIcon(QIcon(":/actions/editcut2.png"));
#endif
		action->setShortcut(QKeySequence::Cut);
		//action->zetStatusTip(tr("Cuts entities to the clipboard"));
    }
    return action;
}



void WF_EditCopy::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}



void WF_EditCopy::trigger() {

    PF_Modification m(*container, graphicView);
    m.copy(referencePoint, !copy);

    graphicView->redraw();
    finish();
    graphicView->killSelectActions();
    init(getStatus()-1);
    PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
}


void WF_EditCopy::mouseMoveEvent(PF_MouseEvent* e) {
    snapPoint(e);
}



void WF_EditCopy::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::LeftButton) {
        PF_CoordinateEvent ce(snapPoint(e));
        coordinateEvent(&ce);
    } else if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    }
}



void WF_EditCopy::coordinateEvent(PF_CoordinateEvent* e) {
    if (e==NULL) {
        return;
    }

    referencePoint = e->getCoordinate();
    trigger();
}



void WF_EditCopy::updateMouseButtonHints() {
    switch (getStatus()) {
    case SetReferencePoint:
        PF_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
                                            tr("Cancel"));
        break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}



void WF_EditCopy::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::CadCursor);
}



void WF_EditCopy::updateToolBar() {
    if (!isFinished()) {
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSnap);
    } else {
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarMain);
    }
}


// EOF
